﻿using System;
using System.Collections.Generic;

namespace sinetd
{
    public class Config : Dictionary<string, string>
    {
        public void SetDefault(string name, string value)
        {
            this["default_" + name] = value;
        }

        public string GetDefault(string name)
        {
            return this.ContainsKey("default_" + name) ? this["default_" + name] : "";
        }

        public Int32 GetInt32(string name)
        {
            return Int32.Parse(this.ContainsKey(name) ? this[name] : this.GetDefault(name));
        }

        public void SetInt32(string name, int value)
        {
            this[name] = value.ToString();
        }

        public string GetString(string name)
        {
            return this.ContainsKey(name) ? this[name] : this.GetDefault(name);
        }

        public void SetString(string name, string value)
        {
            this[name] = value;
        }

        public bool GetBoolean(string name)
        {
            return Boolean.Parse(this.ContainsKey(name) ? this[name] : this.GetDefault(name));
        }

        public void SetBoolean(string name, bool value)
        {
            this[name] = value.ToString();
        }
    }
}
